package com.lsw.jgyf.httpapi;

import com.google.gson.JsonObject;
import com.lsw.jgyf.model.BankCardModel;
import com.lsw.jgyf.model.BannerModel;
import com.lsw.jgyf.model.BaseModel;
import com.lsw.jgyf.model.ContractPhoneModel;
import com.lsw.jgyf.model.CreateOrderModel;
import com.lsw.jgyf.model.FenqichanpingModel;
import com.lsw.jgyf.model.FenqigongsiModel;
import com.lsw.jgyf.model.FrontCardModel;
import com.lsw.jgyf.model.FujiaxianModel;
import com.lsw.jgyf.model.HeadModel;
import com.lsw.jgyf.model.HomeFragment1Model;
import com.lsw.jgyf.model.JsonBean;
import com.lsw.jgyf.model.LoginModel;
import com.lsw.jgyf.model.MoreOptionsModel;
import com.lsw.jgyf.model.OrderAuditModel;
import com.lsw.jgyf.model.OrderDetailsModel;
import com.lsw.jgyf.model.OrderModel;
import com.lsw.jgyf.model.PhoneDetailsModel;
import com.lsw.jgyf.model.PhoneModel;
import com.lsw.jgyf.model.ScreenModel;
import com.lsw.jgyf.model.ShopModel;
import com.lsw.jgyf.model.StagingCompanyDetailsModel;
import com.lsw.jgyf.model.StagingCompanyModel;
import com.lsw.jgyf.rxjava.RxSchedulers;
import com.lsw.jgyf.ui.fragment.HomeFragment1;
import com.lsw.util.StringUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2018/7/13 0013.
 */

public class HttpApi {
    HttpService httpService;

    @Inject
    public HttpApi(HttpService httpService) {
        this.httpService = httpService;
    }

    public Observable<BaseModel<LoginModel>> login(String phone, String password) {
        return httpService.login(phone, password)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<LoginModel>> loginphone(String phone, String code) {
        return httpService.loginphone(phone, code)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<LoginModel>> registerDianyuan(String store_id, String username, String code, String password, String password_confirmation, String phone) {
        return httpService.registerDianyuan(store_id, username, code, password, password_confirmation, phone)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<LoginModel>> registerDianzhang(String store_num, String name, String store_phone, String province_id, String city_id, String area_id, String address, String control_username, String control_mobile, String clerk_username, String clerk_mobile, String code, String password, String password_confirmation) {
        return httpService.registerDianzhang(store_num, name, store_phone, province_id, city_id, area_id, address, control_username, control_mobile, clerk_username, clerk_mobile, code, password, password_confirmation)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<List<ShopModel>>> getShop() {
        return httpService.getShop()
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<List<JsonBean>>> getAddress() {
        return httpService.getAddress()
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<LoginModel>> ChangePassWord(String old_password, String password, String password_confirmation) {
        return httpService.ChangePassWord(old_password, password, password_confirmation)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<List<StagingCompanyModel>>> StagingCompany(String page, String name) {
        return httpService.StagingCompany(page, name)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<StagingCompanyDetailsModel>> StagingCompanyDetails(String id) {
        return httpService.StagingCompanyDetails(id)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<PhoneModel>> PhoneList(String page, String name, String brand_id, String min_price, String max_price, String order_by,String is_contract) {
        return httpService.PhoneList(page, name, brand_id, min_price, max_price, order_by,is_contract)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<BannerModel>> getBanner() {
        return httpService.getBanner()
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<ScreenModel>> getScreen() {
        return httpService.getScreen()
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<PhoneDetailsModel>> getPhoneDetails(String id) {
        return httpService.getPhoneDetails(id)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<List<Object>>> SendCode(String mobile, String type) {
        return httpService.SendCode(mobile, type)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<BankCardModel>> UpBankcard(String url) {
        File file = new File(url);
        RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), file);
        MultipartBody.Part part = MultipartBody.Part.createFormData("bank_card", file.getName(), requestBody);
        return httpService.UpBankcard(part)
                .compose(RxSchedulers.observableTransformer());
    }

    public Observable<BaseModel<FrontCardModel>> upFrontcardImage(String url) {
        File file = new File(url);
        RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), file);
        MultipartBody.Part part = MultipartBody.Part.createFormData("front", file.getName(), requestBody);
        return httpService.upFrontcardImage(part)
                .compose(RxSchedulers.observableTransformer());
    }

    public Observable<BaseModel<FrontCardModel>> upBackcardImage(String url, String card_num) {
        File file = new File(url);
        RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), file);
        MultipartBody.Builder builder = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)//表单类型
                .addFormDataPart("card_num", card_num)
                .addFormDataPart("back", file.getName(), requestBody);
        List<MultipartBody.Part> parts = builder.build().parts();
        return httpService.upBackcardImage(parts)
                .compose(RxSchedulers.observableTransformer());
    }

    public Observable<BaseModel<List<FenqigongsiModel>>> selectcompany(String periods, String insurance_id) {
        return httpService.selectcompany(periods, insurance_id)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<List<ContractPhoneModel>>> selecttaocan(String operator_id) {
        return httpService.selecttaocan(operator_id)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<List<FenqichanpingModel>>> selectproduct(String periods, String insurance_id, String company_id) {
        return httpService.selectproduct(periods, insurance_id, company_id)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<List<MoreOptionsModel>>> more_case(String price, String insurance_id, String first_money, String num, String periods) {
        return httpService.more_case(price, insurance_id, first_money, num, periods)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<List<FujiaxianModel>>> Fujiaxian(String periods) {
        return httpService.Fujiaxian(periods)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<CreateOrderModel>> CreateOrder(String phone_id,
                                                               String memory,
                                                               String color,
                                                               String num,
                                                               String is_new,
                                                               String mobile,
                                                               String packageX,
                                                               String price,
                                                               String periods,
                                                               String insurance_id,
                                                               String company_id,
                                                               String company_product_id,
                                                               String first_money,
                                                               String name,
                                                               String sex,
                                                               String id_number,
                                                               String address,
                                                               String issue_time,
                                                               String end_time,
                                                               String issue,
                                                               String bank_name,
                                                               String bank_card_number,
                                                               String buy_type,
                                                               String discount_price,
                                                               String package_expenses) {
        return httpService.CreateOrder(phone_id, memory, color, num, is_new, mobile, packageX, price, periods, insurance_id, company_id, company_product_id, first_money, name, sex, id_number, address, issue_time, end_time, issue, bank_name, bank_card_number, buy_type, discount_price, package_expenses)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<OrderModel>> getOrder(String search, String status, String page) {
        return httpService.getOrder(search, status, page)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<OrderDetailsModel>> getOrderDetails(String id) {
        return httpService.getOrderDetails(id)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<LoginModel>> ForgetPassWord(String mobile, String code, String password, String password_confirmation) {
        return httpService.ForgetPassWord(mobile, code, password, password_confirmation)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<HomeFragment1Model>> getindex(String name, String page) {
        return httpService.getindex(name, page)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<OrderAuditModel>> AuditFailure(String id, String deny_reason) {
        return httpService.AuditFailure(id, deny_reason)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<OrderAuditModel>> AuditSuccess(String id) {
        return httpService.AuditSuccess(id)
                .compose(RxSchedulers.observableTransformer);
    }

    public Observable<BaseModel<HeadModel>> uphead(String url) {
        File file = new File(url);
        RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), file);
        MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
        return httpService.uphead(part)
                .compose(RxSchedulers.observableTransformer());
    }

}
